Completed
Push — master ( e193d1...415e1b )
by Justin
01:32
created

does not copy instancesꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 9.4285
1
var assert = require('chai').assert,
2
    GedcomX = require('../../');
3
4
describe('AtomSource', function(){
5
  
6
  var json = {
7
    authors: [
8
      {
9
        name: 'author',
10
        email: '[email protected]'
11
      }  
12
    ],
13
    contributors: [
14
      {
15
        name: 'contributor',
16
        email: '[email protected]'
17
      }  
18
    ],
19
    categories: [
20
      {
21
        scheme: 'scheme',
22
        term: 'term',
23
        label: 'label'
24
      }
25
    ],
26
    generator: {
27
      uri: 'uri',
28
      version: 'version',
29
      value: 'value'
30
    },
31
    icon: 'icon',
32
    id: 'id',
33
    links: {
34
      rel: {
35
        href: 'href'
36
      }
37
    },
38
    logo: 'logo',
39
    rights: 'rights',
40
    subtitle: 'subtitle',
41
    title: 'title',
42
    updated: 123456789
43
  };
44
  
45
  it('Create plain', function(){
46
    assert.instanceOf(new GedcomX.AtomSource(), GedcomX.AtomSource, 'An instance of AtomSource is not returned when calling the constructor with new.');
47
    assert.instanceOf(GedcomX.AtomSource(), GedcomX.AtomSource, 'An instance of AtomSource is not returned when calling the constructor without new.');
48
  });
49
  
50
  it('Create with JSON', function(){
51
    tests(GedcomX.AtomSource(json));
52
  });
53
  
54
  it('Build', function(){
55
    tests(GedcomX.AtomSource()
56
      .addAuthor(
57
        GedcomX.AtomPerson()
58
          .setName('author')
59
          .setEmail('[email protected]')
60
      )
61
      .addContributor(
62
        GedcomX.AtomPerson()
63
          .setName('contributor')
64
          .setEmail('[email protected]')
65
      )
66
      .addCategory(
67
        GedcomX.AtomCategory()
68
          .setScheme('scheme')
69
          .setTerm('term')
70
          .setLabel('label')
71
      )
72
      .setGenerator(
73
        GedcomX.AtomGenerator()
74
          .setUri('uri')
75
          .setVersion('version')
76
          .setValue('value')
77
      )
78
      .setIcon('icon')
79
      .setId('id')
80
      .addLink(
81
        GedcomX.Link()
82
          .setRel('rel')
83
          .setHref('href')
84
      )
85
      .setLogo('logo')
86
      .setRights('rights')
87
      .setSubtitle('subtitle')
88
      .setTitle('title')
89
      .setUpdated(123456789)
90
    );
91
  });
92
  
93
  it('toJSON', function(){
94
    assert.deepEqual(GedcomX.AtomSource(json).toJSON(), json);
95
  });
96
  
97
  it('constructor does not copy instances', function(){
98
    var obj1 = GedcomX.AtomSource();
99
    var obj2 = GedcomX.AtomSource(obj1);
100
    assert.strictEqual(obj1, obj2);
101
  });
102
  
103
});
104
105
function tests(source){
106
  assert.equal(source.getAuthors().length, 1);
107
  var author = source.getAuthors()[0];
108
  assert.equal(author.getName(), 'author');
109
  assert.equal(author.getEmail(), '[email protected]');
110
  
111
  assert.equal(source.getContributors().length, 1);
112
  var contributor = source.getContributors()[0];
113
  assert.equal(contributor.getName(), 'contributor');
114
  assert.equal(contributor.getEmail(), '[email protected]');
115
  
116
  assert.equal(source.getCategories().length, 1);
117
  var category = source.getCategories()[0];
118
  assert.equal(category.getScheme(), 'scheme');
119
  assert.equal(category.getTerm(), 'term');
120
  assert.equal(category.getLabel(), 'label');
121
  
122
  var generator = source.getGenerator();
123
  assert.equal(generator.getUri(), 'uri');
124
  assert.equal(generator.getVersion(), 'version');
125
  assert.equal(generator.getValue(), 'value');
126
  
127
  assert.equal(source.getIcon(), 'icon');
128
  assert.equal(source.getId(), 'id');
129
  assert.equal(source.getLinks().length, 1);
130
  assert.equal(source.getLink('rel').getHref(), 'href');
131
  assert.equal(source.getLogo(), 'logo');
132
  assert.equal(source.getRights(), 'rights');
133
  assert.equal(source.getSubtitle(), 'subtitle');
134
  assert.equal(source.getTitle(), 'title');
135
  assert.equal(source.getUpdated().getTime(), 123456789);
136
}